import os
import pyautogui
import uuid
import time
import threading  # 导入threading模块
import datetime  # 导入datetime模块 
from paddleocr import PaddleOCR
from PIL import ImageGrab 


def makdir(path):
    try:
        isExists = os.path.exists(path)
        # 判断是否存在文件夹
        if not isExists:
            # 不存在创建
            os.makedirs(path)
            print(path+'文件夹创建成功！')
    except Exception as e:
        print(e)

def grab_screenshot_area(x, y,x2,y2):
    # print(os.getcwd())
    path = os.getcwd()
    makdir(path+'\\pics\\')
    area = (x, y,x2,y2)   # 这里是设置截图范围的区域
    shot = ImageGrab.grab(area)
    filename = path+'\\pics\\'+str(uuid.uuid1())+'.png'
    shot.save(filename)
    # print(filename)
    return filename 

def getName(filename):
    ocr = PaddleOCR(use_angle_cls=True, lang="ch") # need to run only once to download and load model into memory
# result = ocr.ocr('pics\\1.png', cls=True)
    result = ocr.ocr(filename, cls=True)
    name=''
    # print(result)
    for line in result:
        for item in line:
            name+=(item[1][0]) 
    os.remove(filename)    
    return name 

def job():  # 定义方法
    
    # 移动到研习按钮
    pyautogui.moveTo(1281, 708)
    # 点击研习按钮
    pyautogui.click()
    time.sleep(0.5) 
    for num in range(0, 12):
        pyautogui.moveTo(1364, 1074)
        pyautogui.click()
        time.sleep(4)  
        pyautogui.click()
        time.sleep(0.5)  
  

if __name__ == "__main__":   
    job()